package com.lm.shop.order.controller;

import com.lm.shop.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsk
 * @version 1.0.0
 * @ClassName OrderController.java
 * @Description 订单控制层
 * @createTime 2022年10月19日 19:17:00
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Resource
    private DiscoveryClient discoveryClient;

    @GetMapping("/getOrderByProductId")
    public R getOrderByProductId(){
        List<String> services = discoveryClient.getServices();
        services.forEach(System.out::println);
        // 获得服务名下的实例列表
        List<ServiceInstance> instances = discoveryClient.getInstances("SHOP-PRODUCT");
        instances.forEach(instance -> {
            System.out.println(instance.getServiceId() + "\t" + instance.getHost() + "\t" + instance.getPort() + "\t" + instance.getUri());
        });
        return R.ok().setData(instances);
    }
}
